#include<bits/stdc++.h>
using namespace std;
int mod;
long long qmi(long long a,int b)
{
	long long res = 1;
	while(b)
	{
		if(b & 1) (res *= a) %= mod;
		(a *= a) %= mod;
		b >>= 1;
	}
	return res;
}
long long fac[10000011],exfac[10000011];
long long C(int n,int m)
{
	return fac[n] * exfac[m] % mod * exfac[n - m] % mod;
}
long long A(int n,int m)
{
	return fac[n] * exfac[n - m] % mod;
}
int n;
long long f[3011][3011];
long long ans;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	freopen("tree.in","r",stdin);
	freopen("tree.out","w",stdout);
	cin >> n >> mod;
	fac[0] = 1;
	for(int i = 1;i <= n;i++) fac[i] = fac[i - 1] * i % mod;
	exfac[n] = qmi(fac[n],mod - 2);
	for(int i = n;i;i--) exfac[i - 1] = exfac[i] * i % mod;
	for(int i = 1;i <= n;i++)
		f[n][i] = 1;
	for(int i = n - 1;i;i--)
		for(int j = 1;j <= i;j++)
			for(int k = 1,mi = j;i + k <= n;k++,mi = 1ll * mi * j % mod)
				f[i][j] = (f[i][j] + f[i + k][k] * C(n - i,k) % mod * mi) % mod;
	for(int i = n,mi = 1;i;i--,mi = (mi + mi) % mod)
		ans = (ans + A(n,i) * f[i][i] % mod * mi) % mod;
	cout << ans;
	return 0;
}
